package com.example.saveqq;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private Button btn_login;
    private EditText et_Account, et_Passwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_login = (Button) findViewById(R.id.btn_login);
        et_Account = (EditText) findViewById(R.id.et_Account);
        et_Passwd = (EditText) findViewById(R.id.et_Passwd);

        //Map<String,String> userInfo = DataSaveQQ.getUserInfo(MainActivity.this);
        Map<String,String> userInfo = DataSaveQQ.spGetUserInfo(MainActivity.this);
        if(userInfo != null){
            et_Account.setText(userInfo.get("account"));
            et_Passwd.setText(userInfo.get("pwd"));
        }

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()){
                    case R.id.btn_login:
                        String account = et_Account.getText().toString().trim();
                        String pwd = et_Passwd.getText().toString().trim();
                        if(TextUtils.isEmpty(account)){
                            Toast.makeText(MainActivity.this,"请输入账号",Toast.LENGTH_SHORT).show();
                            return;
                        }
                        if(TextUtils.isEmpty(pwd)){
                            Toast.makeText(MainActivity.this,"请输入密码",Toast.LENGTH_SHORT).show();
                            return;
                        }
                        //DataSaveQQ.saveUserInfo(MainActivity.this,account,pwd);
                        DataSaveQQ.spSaveUserInfo(MainActivity.this,account,pwd);
                        break;
                }
            }
        });
    }
}